import master from './master/mutations';
import buyShow from './buyShow/mutations';
import Vue from 'vue';
export default {
    ...master,
    ...buyShow,
    async updateStoreMenu (state, menu) {
        let menuType = 1;
        if (window.location.href.includes('/store/master/')) {
            menuType = 5;
        } else if (window.location.href.includes('/store/buyShow/')) {
            menuType = 4;
        } else if (window.location.href.includes('/store/goods/')) {
            menuType = 3;
        } else if (window.location.href.includes('/store/panorama/')) {
            menuType = 1;
        } else if (window.location.href.includes('/store/playDirect/')) {
            menuType = 6;
        } else if (window.location.href.includes('/store/promotion/')) {
            menuType = 2;
        }
        let tempObj = {};
        let getterMenu = this.getters.getterStoreMenu
        if (menu && menu.menus) {
            menu.menus.forEach(async (menusItem, menusIndex) => {
                if (menuType == menusItem.menuType) {
                    tempObj = {
                        menuType: menusItem.menuType,
                        menuId: menusItem.menuId,
                        menus: menu.menus
                    };
                    try {
                        state.store = Object.assign({}, state.store, tempObj);
                        window.sessionStorage.setItem('storeMenu', state.store);
                    } catch (e) {
                    }
                }
            });
        } else if (getterMenu) {
            if (getterMenu && getterMenu.menus) {
                getterMenu.menus.forEach(async (menusItem, menusIndex) => {
                    if (menuType == menusItem.menuType) {
                        tempObj = {
                            menuType: menusItem.menuType,
                            menuId: menusItem.menuId,
                            menus: getterMenu.menus
                        };
                        try {
                            state.store = Object.assign({}, state.store, tempObj);
                            window.sessionStorage.setItem('storeMenu', state.store);
                        } catch (e) {
                        }
                    }
                });
            }
        } else {
            try {
                console.log(menu, 'menu')
                state.store = Object.assign({}, state.store, menu);
                window.sessionStorage.setItem('storeMenu', state.store);
            } catch (e) {
            }
        }

    },
    isLike (state, obj) {
        console.log(obj, 'like')
        let that = this;
        // http://192.168.1.163:7280/nw_api/api/zh/v1.00/like/user/2004/do?likeType=2&&likeKey=3677
        //http://192.168.1.163:7280/nw_api/api/zh/v1.00/like/user/2004/do?likeType=2&&likeKey=31
        //0-主评论  1-子评论  2-店铺官网媒体   3-店铺商品  4-店铺活动  5-买家秀  6-大师  10-用户多媒体信息
        //1-店铺官网媒体  2-店铺活动  3-店铺商品    4-买家秀  5-大师

        let likeType = -1;
        /*主子评论点赞*/
        if (obj && Object.keys(obj).includes('mainkey')) {
            if (Object.keys(obj).includes('subKey')) {
                likeType = 1;
            } else {
                likeType = 0;
            }
        } else {
            switch (obj.likeType) {
                case 1:
                    likeType = 2;
                    break;
                case 2:
                    likeType = 4;
                    break;
                case 3:
                    likeType = 3;
                    break;
                case 4:
                    likeType = 5;
                    break;
                case 5:
                    likeType = 6;
                    break;
                /*媒体点赞*/
                default:
                    likeType = 10;
                    break;
            }
        }
        obj = Object.assign({}, obj, { likeType })
        console.log(obj, 'ooooooooooooo')
        this.dispatch('doLikeApi', obj)
        // let url = '';
        // if (obj.isLike) {
        //     url = `${this.NW_API_API_LOCALE_VERSION}/like/user/${this.userId}/do?likeType=${likeType}&likeKey=${obj.likeKey}`
        // } else {
        //     url = `${this.NW_API_API_LOCALE_VERSION}/like/user/${this.userId}/cancel?likeType=${likeType}&likeKey=${obj.likeKey}`
        // }
        // this.xurl.put(url).then((data) => {
        //     if (data.success) {
        //         console.log(data)
        //     } else {
        //         console.log("点赞失败")
        //     }
        // })
    },
    shareShow (state, boolean = true) {
        state.shareBordShow = boolean;
    },
    //领取红包后关注样式改变
    setConcerned (state, val) {
        console.log(val, '红包状态');
        state.concerned = val
    },
}